package com.yxx.controller.admin;

import com.yxx.medicinecommon.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @author yuxiangxun
 * @date 2024/9/26
 * @apiNote
 */
@RestController
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "药店营业状态")
public class ShopController {

    private final String STATUS_KEY = "_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 修改/设置药店营业状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("修改/设置药店营业状态")
    public ResponseResult updateShopStatus(@PathVariable("status") Integer status){
        redisTemplate.opsForValue().set(STATUS_KEY,status,24, TimeUnit.HOURS);
        return ResponseResult.success();
    }

    @GetMapping("/status")
    @ApiOperation("查询/查看药店营业状态")
    public ResponseResult<Integer> showShopStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(STATUS_KEY);
        return ResponseResult.success(status);
    }

}
